package com.bookcloud.java21.chapter5.嵌套类和内部类57;

public class OuterClass {
  // 静态的嵌套类
  static class StaticNestedClass {
    public void display() {
      System.out.println("这是静态的嵌套类");
    }

    public static void staticMethod() {
      System.out.println("这是静态的嵌套类的静态方法");
    }
  }

  // 非静态的嵌套类
  class NonStaticNestedClass {
    public void display() {
      System.out.println("这是非静态的嵌套类");
    }
  }

  // 方法局部的嵌套类
  public void methodLocalNestedClass() {
    class MethodLocalNestedClass {
      public void display() {
        System.out.println("这是方法局部的嵌套类");
      }
    }
    MethodLocalNestedClass methodLocalNested = new MethodLocalNestedClass();
    methodLocalNested.display();
  }

  // 匿名内部类
  public void anonymousInnerClass() {
    // 实现了Runnable接口的匿名内部类
    Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            System.out.println("这是匿名内部类");
          }
        };
    runnable.run();
  }
}
